package JUCtest;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch count = new CountDownLatch(8);
        for (int i = 0; i < 8; i++) {
            int id = i;
            Thread thread = new Thread(() -> {
                System.out.println("开始任务" + id);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("任务" + id + "结束");
                count.countDown();
            });
            thread.start();
        }
        count.await();
        System.out.println("所有任务结束");
    }
}
